package com.yc.home.cloudother.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.entity.Exam;
import com.yc.entity.ExamDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lzk
 * @since 2024-10-12
 */
public interface ExamMapper extends BaseMapper<Exam> {

    //关联查询
    @Select("select * from exam where pid=#{pid} and uid=#{uid}")
    @Results(id="rm1",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "id",property = "details", many = @Many(
                            select = "selectDetailByPid"
                    ))
            })
    Exam findById(@Param("pid") int pid, @Param("uid") int uid);

    @Select("select * from exam_detail where eid=#{eid}")
    @Results(id="rm2",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "qid",property = "qid"),
                    @Result(column = "qid",property = "question", one = @One(
                            select = "com.yc.home.cloudother.mapper.QuestionMapper.selectById"
                    ))
            })
    List<ExamDetail> selectDetailByPid(int eid);

    //关联查询
    @Select("select * from exam where pid=#{pid} and uid=#{uid} and cid=#{cid}")
    @Results(id="rm3",
            value={
                    @Result(column = "id",property = "id", id = true),
                    @Result(column = "id",property = "details", many = @Many(
                            select = "selectDetailByPid"
                    ))
            })
    Exam findByCid(@Param("pid") int pid, @Param("uid") int uid, @Param("cid") int cid);

}
